using System;
using System.Linq;
using System.Runtime.Serialization;
using System.Data.Objects.DataClasses;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Collections.Generic;
using System.Data.Objects;
using System.Text;
using Acme.Northwind.EFDAL;
using nHydrate.EFCore.DataAccess;
using nHydrate.EFCore.EventArgs;
using System.Text.RegularExpressions;
using System.Linq.Expressions;
using System.Data.Linq;

namespace Acme.Northwind.EFDAL.Entity
{
	/// <summary>
	/// The collection to hold 'OrderDetail' entities
	/// </summary>
	[System.CodeDom.Compiler.GeneratedCode("nHydrateModelGenerator", "5.0.1.100")]
	[EdmEntityTypeAttribute(NamespaceName="Acme.Northwind.EFDAL.Entity", Name="OrderDetail")]
	[Serializable()]
	[DataContractAttribute(IsReference = true)]
	[nHydrate.EFCore.Attributes.FieldNameConstantsAttribute(typeof(Acme.Northwind.EFDAL.Entity.OrderDetail.FieldNameConstants))]
	[System.ComponentModel.DataAnnotations.MetadataType(typeof(Acme.Northwind.EFDAL.Interfaces.Entity.Metadata.OrderDetailMetadata))]
	[nHydrate.EFCore.Attributes.EntityMetadata("OrderDetail", false, true, true, true, "", true, false, false, "dbo")]
	public partial class OrderDetail : nHydrate.EFCore.DataAccess.NHEntityObject, nHydrate.EFCore.DataAccess.IBusinessObject, Acme.Northwind.EFDAL.IEntityWithContext, Acme.Northwind.EFDAL.Interfaces.Entity.IOrderDetail, System.ICloneable, nHydrate.EFCore.DataAccess.IAuditable, System.IEquatable<Acme.Northwind.EFDAL.Interfaces.Entity.IOrderDetail>
	{
		#region FieldNameConstants Enumeration

		/// <summary>
		/// Enumeration to define each property that maps to a database field for the 'OrderDetail' table.
		/// </summary>
		public enum FieldNameConstants
		{
			/// <summary>
			/// Field mapping for the 'Discount' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'Discount' property")]
			Discount,
			/// <summary>
			/// Field mapping for the 'OrderID' property
			/// </summary>
			[nHydrate.EFCore.Attributes.PrimaryKeyAttribute()]
			[System.ComponentModel.ReadOnlyAttribute(true)]
			[System.ComponentModel.Description("Field mapping for the 'OrderID' property")]
			OrderID,
			/// <summary>
			/// Field mapping for the 'ProductID' property
			/// </summary>
			[nHydrate.EFCore.Attributes.PrimaryKeyAttribute()]
			[System.ComponentModel.ReadOnlyAttribute(true)]
			[System.ComponentModel.Description("Field mapping for the 'ProductID' property")]
			ProductID,
			/// <summary>
			/// Field mapping for the 'Quantity' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'Quantity' property")]
			Quantity,
			/// <summary>
			/// Field mapping for the 'UnitPrice' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'UnitPrice' property")]
			UnitPrice,
			/// <summary>
			/// Field mapping for the 'CreatedBy' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'CreatedBy' property")]
			CreatedBy,
			/// <summary>
			/// Field mapping for the 'CreatedDate' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'CreatedDate' property")]
			CreatedDate,
			/// <summary>
			/// Field mapping for the 'ModifiedBy' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'ModifiedBy' property")]
			ModifiedBy,
			/// <summary>
			/// Field mapping for the 'ModifiedDate' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'ModifiedDate' property")]
			ModifiedDate,
		}
		#endregion

		#region Constructors

		/// <summary>
		/// Method called when an instance of this class is created
		/// </summary>
		partial void OnCreated();

		/// <summary>
		/// Initializes a new instance of the Acme.Northwind.EFDAL.Entity.OrderDetail class
		/// </summary>
		public OrderDetail()
		{
			_discount = 0;
			_quantity = 1;
			_unitPrice = 0M;
			this.OnCreated();
		}

		/// <summary>
		/// Initializes a new instance of the Acme.Northwind.EFDAL.Entity.OrderDetail class with a defined primary key
		/// </summary>
		public OrderDetail(int orderID, int productID)
		{
			_discount = 0;
			_quantity = 1;
			_unitPrice = 0M;
			_orderID = orderID;
			_productID = productID;
			this.OnCreated();
		}

		#endregion

		#region Properties

		/// <summary>
		/// The property that maps back to the database 'Order Details.Discount' field
		/// </summary>
		/// <remarks>Field: [Order Details].[Discount], Not Nullable, Default Value: 0</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = false)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("Discount")]
		public virtual System.Single Discount
		{
			get { return _discount; }
			set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<System.Single>(value, "Discount");
				//this.OnDiscountChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("Discount");
				_discount = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("Discount");
				//this.OnDiscountChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Order Details.OrderID' field
		/// </summary>
		/// <remarks>Field: [Order Details].[OrderID], Not Nullable, Primary Key, Unique, Indexed</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = true, IsNullable = false)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("OrderID")]
		[System.ComponentModel.DataAnnotations.Key()]
		[System.ComponentModel.ReadOnly(true)]
		public virtual int OrderID
		{
			get { return _orderID; }
			set
			{
				ReportPropertyChanging("OrderID");
				_orderID = value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("OrderID");
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Order Details.ProductID' field
		/// </summary>
		/// <remarks>Field: [Order Details].[ProductID], Not Nullable, Primary Key, Unique, Indexed</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = true, IsNullable = false)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("ProductID")]
		[System.ComponentModel.DataAnnotations.Key()]
		[System.ComponentModel.ReadOnly(true)]
		public virtual int ProductID
		{
			get { return _productID; }
			set
			{
				ReportPropertyChanging("ProductID");
				_productID = value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("ProductID");
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Order Details.Quantity' field
		/// </summary>
		/// <remarks>Field: [Order Details].[Quantity], Not Nullable, Default Value: 1</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = false)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("Quantity")]
		public virtual short Quantity
		{
			get { return _quantity; }
			set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<short>(value, "Quantity");
				//this.OnQuantityChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("Quantity");
				_quantity = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("Quantity");
				//this.OnQuantityChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Order Details.UnitPrice' field
		/// </summary>
		/// <remarks>Field: [Order Details].[UnitPrice], Not Nullable, Default Value: 0</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = false)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("UnitPrice")]
		public virtual decimal UnitPrice
		{
			get { return _unitPrice; }
			set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<decimal>(value, "UnitPrice");
				//this.OnUnitPriceChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("UnitPrice");
				_unitPrice = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("UnitPrice");
				//this.OnUnitPriceChanged(eventArg);
			}
		}

		/// <summary>
		/// The audit field for the 'Created By' parameter.
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		public virtual string CreatedBy
		{
			get { return _createdby; }
			protected internal set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "CreatedBy");
				//OnCreatedByChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("CreatedBy");
				_createdby = eventArg.Value;
				ReportPropertyChanged("CreatedBy");
				//OnCreatedByChanged(eventArg);
			}
		}

		/// <summary>
		/// The internal reference variable for the 'createdby' property
		/// </summary>
		protected string _createdby;

		/// <summary>
		/// The audit field for the 'Created Date' parameter.
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		public virtual DateTime? CreatedDate
		{
			get { return _createddate; }
			protected internal set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<DateTime?>(value, "CreatedDate");
				//OnCreatedDateChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("CreatedDate");
				_createddate = eventArg.Value;
				ReportPropertyChanged("CreatedDate");
				//OnCreatedDateChanged(eventArg);
			}
		}

		/// <summary>
		/// The internal reference variable for the 'createddate' property
		/// </summary>
		protected DateTime? _createddate;

		/// <summary>
		/// The audit field for the 'Modified By' parameter.
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		public virtual string ModifiedBy
		{
			get { return _modifiedby; }
			protected internal set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "ModifiedBy");
				//OnModifiedByChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("ModifiedBy");
				_modifiedby = eventArg.Value;
				ReportPropertyChanged("ModifiedBy");
				//OnModifiedByChanged(eventArg);
			}
		}

		/// <summary>
		/// The internal reference variable for the 'modifiedby' property
		/// </summary>
		protected string _modifiedby;

		/// <summary>
		/// The audit field for the 'Modified Date' parameter.
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		public virtual DateTime? ModifiedDate
		{
			get { return _modifieddate; }
			protected internal set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<DateTime?>(value, "ModifiedDate");
				//OnModifiedDateChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("ModifiedDate");
				_modifieddate = eventArg.Value;
				ReportPropertyChanged("ModifiedDate");
				//OnModifiedDateChanged(eventArg);
			}
		}

		/// <summary>
		/// The internal reference variable for the 'modifieddate' property
		/// </summary>
		protected DateTime? _modifieddate;

		/// <summary>
		/// The audit field for the 'Timestamp' parameter.
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		public virtual byte[] Timestamp
		{
			get { return _timestamp; }
			protected internal set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<byte[]>(value, "Timestamp");
				//OnTimestampChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("Timestamp");
				_timestamp = eventArg.Value;
				ReportPropertyChanged("Timestamp");
				//OnTimestampChanged(eventArg);
			}
		}

		/// <summary>
		/// The internal reference variable for the 'timestamp' property
		/// </summary>
		protected byte[] _timestamp;

		#endregion

		#region Events

		/// <summary>
		/// The internal reference variable for the 'Discount' property
		/// </summary>
		protected System.Single _discount;

		/// <summary>
		/// The internal reference variable for the 'OrderID' property
		/// </summary>
		protected int _orderID;

		/// <summary>
		/// The internal reference variable for the 'ProductID' property
		/// </summary>
		protected int _productID;

		/// <summary>
		/// The internal reference variable for the 'Quantity' property
		/// </summary>
		protected short _quantity;

		/// <summary>
		/// The internal reference variable for the 'UnitPrice' property
		/// </summary>
		protected decimal _unitPrice;

		#endregion

		#region GetMaxLength

		/// <summary>
		/// Gets the maximum size of the field value.
		/// </summary>
		public static int GetMaxLength(FieldNameConstants field)
		{
			switch (field)
			{
				case FieldNameConstants.Discount:
					return 0;
				case FieldNameConstants.OrderID:
					return 0;
				case FieldNameConstants.ProductID:
					return 0;
				case FieldNameConstants.Quantity:
					return 0;
				case FieldNameConstants.UnitPrice:
					return 0;
			}
			return 0;
		}

		int nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetMaxLength(Enum field)
		{
			return GetMaxLength((FieldNameConstants)field);
		}

		#endregion

		#region GetFieldNameConstants

		System.Type nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetFieldNameConstants()
		{
			return typeof(FieldNameConstants);
		}

		#endregion

		#region GetFieldType

		/// <summary>
		/// Gets the system type of a field on this object
		/// </summary>
		public static System.Type GetFieldType(FieldNameConstants field)
		{
			if (field.GetType() != typeof(FieldNameConstants))
				throw new Exception("The '" + field.GetType().ReflectedType.ToString() + ".FieldNameConstants' value is not valid. The field parameter must be of type 'Acme.Northwind.EFDAL.Entity.OrderDetail.FieldNameConstants'.");

			var array = Enum.GetValues(typeof(FieldNameConstants));
			switch ((FieldNameConstants)field)
			{
				case FieldNameConstants.Discount: return typeof(System.Single);
				case FieldNameConstants.OrderID: return typeof(int);
				case FieldNameConstants.ProductID: return typeof(int);
				case FieldNameConstants.Quantity: return typeof(short);
				case FieldNameConstants.UnitPrice: return typeof(decimal);
			}
			return null;
		}

		System.Type nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetFieldType(Enum field)
		{
			if (field.GetType() != typeof(FieldNameConstants))
				throw new Exception("The '" + field.GetType().ReflectedType.ToString() + ".FieldNameConstants' value is not valid. The field parameter must be of type 'Acme.Northwind.EFDAL.Entity.OrderDetail.FieldNameConstants'.");

			return GetFieldType((Acme.Northwind.EFDAL.Entity.OrderDetail.FieldNameConstants)field);
		}

		#endregion

		#region Get/Set Value

		object nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetValue(System.Enum field)
		{
			return ((nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject)this).GetValue(field, null);
		}

		object nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetValue(System.Enum field, object defaultValue)
		{
			if (field.GetType() != typeof(FieldNameConstants))
				throw new Exception("The '" + field.GetType().ReflectedType.ToString() + ".FieldNameConstants' value is not valid. The field parameter must be of type '" + this.GetType().ToString() + ".FieldNameConstants'.");
			return this.GetValue((FieldNameConstants)field, defaultValue);
		}

		void nHydrate.EFCore.DataAccess.IBusinessObject.SetValue(System.Enum field, object newValue)
		{
			if (field.GetType() != typeof(FieldNameConstants))
				throw new Exception("The '" + field.GetType().ReflectedType.ToString() + ".FieldNameConstants' value is not valid. The field parameter must be of type '" + this.GetType().ToString() + ".FieldNameConstants'.");
			this.SetValue((FieldNameConstants)field, newValue);
		}

		#endregion

		#region PrimaryKey

		/// <summary>
		/// Hold the primary key for this object
		/// </summary>
		protected nHydrate.EFCore.DataAccess.IPrimaryKey _primaryKey = null;
		nHydrate.EFCore.DataAccess.IPrimaryKey nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.PrimaryKey
		{
			get
			{
				if (_primaryKey == null) _primaryKey = new Acme.Northwind.EFDAL.Entity.OrderDetailPrimaryKey(this.OrderID, this.ProductID);
				return _primaryKey;
			}
		}

		#endregion

		#region IsParented

		/// <summary>
		/// Determines if this object is part of a collection or is detached
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		public virtual bool IsParented
		{
		  get { return (this.EntityState != System.Data.EntityState.Detached); }
		}

		#endregion

		#region Clone

		/// <summary>
		/// Creates a shallow copy of this object of all simple properties
		/// </summary>
		/// <returns></returns>
		public virtual object Clone()
		{
			var newItem = new OrderDetail();
			newItem._discount = this._discount;
			newItem._quantity = this._quantity;
			newItem._unitPrice = this._unitPrice;
			return newItem;
		}

		#endregion

		#region IsEquivalent

		/// <summary>
		/// Determines if all of the fields for the specified object exactly matches the current object.
		/// </summary>
		/// <param name="item">The object to compare</param>
		public override bool IsEquivalent(nHydrate.EFCore.DataAccess.INHEntityObject item)
		{
			if (item == null) return false;
			if (!(item is Acme.Northwind.EFDAL.Interfaces.Entity.IOrderDetail)) return false;
			var o = item as Acme.Northwind.EFDAL.Interfaces.Entity.IOrderDetail;
			return (
				o.Discount == this.Discount &&
				o.OrderID == this.OrderID &&
				o.ProductID == this.ProductID &&
				o.Quantity == this.Quantity &&
				o.UnitPrice == this.UnitPrice
				);
		}

		#endregion

		#region GetValue

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public object GetValue(FieldNameConstants field)
		{
			return GetValue(field, null);
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public object GetValue(FieldNameConstants field, object defaultValue)
		{
			if (field == FieldNameConstants.Discount)
				return this.Discount;
			if (field == FieldNameConstants.OrderID)
				return this.OrderID;
			if (field == FieldNameConstants.ProductID)
				return this.ProductID;
			if (field == FieldNameConstants.Quantity)
				return this.Quantity;
			if (field == FieldNameConstants.UnitPrice)
				return this.UnitPrice;
			if (field == FieldNameConstants.CreatedBy)
				return ((this.CreatedBy == null) ? defaultValue : this.CreatedBy);
			if (field == FieldNameConstants.CreatedDate)
				return ((this.CreatedDate == null) ? defaultValue : this.CreatedDate);
			if (field == FieldNameConstants.ModifiedBy)
				return ((this.ModifiedBy == null) ? defaultValue : this.ModifiedBy);
			if (field == FieldNameConstants.ModifiedDate)
				return ((this.ModifiedDate == null) ? defaultValue : this.ModifiedDate);
			throw new Exception("Field '" + field.ToString() + "' not found!");
		}

		#endregion

		#region SetValue

		/// <summary>
		/// Assigns a value to a field on this object.
		/// </summary>
		/// <param name="field">The field to set</param>
		/// <param name="newValue">The new value to assign to the field</param>
		public void SetValue(FieldNameConstants field, object newValue)
		{
			SetValue(field, newValue, false);
		}

		/// <summary>
		/// Assigns a value to a field on this object.
		/// </summary>
		/// <param name="field">The field to set</param>
		/// <param name="newValue">The new value to assign to the field</param>
		/// <param name="fixLength">Determines if the length should be truncated if too long. When false, an error will be raised if data is too large to be assigned to the field.</param>
		public void SetValue(FieldNameConstants field, object newValue, bool fixLength)
		{
			if (field == FieldNameConstants.Discount)
			{
				if (newValue == null)
				{
					throw new Exception("Field 'Discount' does not allow null values!");
				}
				else
				{
					if (newValue is string)
					{
						this.Discount = System.Single.Parse((string)newValue);
					} else if (!(newValue is System.Single)) {
						this.Discount = System.Single.Parse(newValue.ToString());
					}
					else if (newValue is nHydrate.EFCore.DataAccess.IBusinessObject)
					{
						throw new Exception("An invalid object of type 'IBusinessObject' was passed in. Perhaps a relationship was not enforced correctly.");
					}
					else
					this.Discount = (System.Single)newValue;
				}
			}
			else if (field == FieldNameConstants.OrderID)
			{
				throw new Exception("Field '" + field.ToString() + "' is a primary key and cannot be set!");
			}
			else if (field == FieldNameConstants.ProductID)
			{
				throw new Exception("Field '" + field.ToString() + "' is a primary key and cannot be set!");
			}
			else if (field == FieldNameConstants.Quantity)
			{
				if (newValue == null)
				{
					throw new Exception("Field 'Quantity' does not allow null values!");
				}
				else
				{
					if (newValue is string)
					{
						this.Quantity = short.Parse((string)newValue);
					} else if (!(newValue is short)) {
						this.Quantity = short.Parse(newValue.ToString());
					}
					else if (newValue is nHydrate.EFCore.DataAccess.IBusinessObject)
					{
						throw new Exception("An invalid object of type 'IBusinessObject' was passed in. Perhaps a relationship was not enforced correctly.");
					}
					else
					this.Quantity = (short)newValue;
				}
			}
			else if (field == FieldNameConstants.UnitPrice)
			{
				if (newValue == null)
				{
					throw new Exception("Field 'UnitPrice' does not allow null values!");
				}
				else
				{
					if (newValue is string)
					{
						this.UnitPrice = decimal.Parse((string)newValue);
					} else if (!(newValue is decimal)) {
						this.UnitPrice = decimal.Parse(newValue.ToString());
					}
					else if (newValue is nHydrate.EFCore.DataAccess.IBusinessObject)
					{
						throw new Exception("An invalid object of type 'IBusinessObject' was passed in. Perhaps a relationship was not enforced correctly.");
					}
					else
					this.UnitPrice = (decimal)newValue;
				}
			}
			else
				throw new Exception("Field '" + field.ToString() + "' not found!");
		}

		#endregion

		#region Navigation Properties

		/// <summary>
		/// The navigation definition for walking [OrderDetail]->[Order]
		/// Relationship Links: 
		/// [Orders.OrderID = Order Details.OrderID] (Required)
		/// </summary>
		[XmlIgnoreAttribute()]
		[SoapIgnoreAttribute()]
		[EdmRelationshipNavigationPropertyAttribute("Acme.Northwind.EFDAL.Entity", "FK_Order_details_orders_OrderDetail_Order", "Order_details_ordersOrder")]
		public virtual Order Order_details_ordersOrder
		{
			get
			{
				var retval = Order_details_ordersOrderReference;
				if (!retval.IsLoaded && this.EntityState != System.Data.EntityState.Added && this.EntityState != System.Data.EntityState.Detached)
				{
					retval.Load();
				}
				return retval.Value;
			}
			set { ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Order>("Acme.Northwind.EFDAL.Entity.FK_Order_details_orders_OrderDetail_Order", "Order_details_ordersOrder").Value = value; }
		}

		/// <summary>
		/// The navigation reference definition for walking Order->OrderDetail
		/// </summary>
		[BrowsableAttribute(false)]
		protected virtual EntityReference<Order> Order_details_ordersOrderReference
		{
			get { return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Order>("Acme.Northwind.EFDAL.Entity.FK_Order_details_orders_OrderDetail_Order", "Order_details_ordersOrder"); }
			set
			{
				if ((value != null))
					((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<Order>("Acme.Northwind.EFDAL.Entity.FK_Order_details_orders_OrderDetail_Order", "Order_details_ordersOrder", value);
			}
		}

		#region IOrderDetail Interface

		Acme.Northwind.EFDAL.Interfaces.Entity.IOrder Acme.Northwind.EFDAL.Interfaces.Entity.IOrderDetail.Order_details_ordersOrder
		{
			get { return this.Order_details_ordersOrder; }
			set { this.Order_details_ordersOrder = (Acme.Northwind.EFDAL.Entity.Order)value; }
		}

		#endregion

		/// <summary>
		/// The navigation definition for walking [OrderDetail]->[Product]
		/// Relationship Links: 
		/// [Products.ProductID = Order Details.ProductID] (Required)
		/// </summary>
		[XmlIgnoreAttribute()]
		[SoapIgnoreAttribute()]
		[EdmRelationshipNavigationPropertyAttribute("Acme.Northwind.EFDAL.Entity", "FK_Order_details_products_OrderDetail_Product", "Order_details_productsProduct")]
		public virtual Product Order_details_productsProduct
		{
			get
			{
				var retval = Order_details_productsProductReference;
				if (!retval.IsLoaded && this.EntityState != System.Data.EntityState.Added && this.EntityState != System.Data.EntityState.Detached)
				{
					retval.Load();
				}
				return retval.Value;
			}
			set { ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Product>("Acme.Northwind.EFDAL.Entity.FK_Order_details_products_OrderDetail_Product", "Order_details_productsProduct").Value = value; }
		}

		/// <summary>
		/// The navigation reference definition for walking Product->OrderDetail
		/// </summary>
		[BrowsableAttribute(false)]
		protected virtual EntityReference<Product> Order_details_productsProductReference
		{
			get { return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Product>("Acme.Northwind.EFDAL.Entity.FK_Order_details_products_OrderDetail_Product", "Order_details_productsProduct"); }
			set
			{
				if ((value != null))
					((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<Product>("Acme.Northwind.EFDAL.Entity.FK_Order_details_products_OrderDetail_Product", "Order_details_productsProduct", value);
			}
		}

		#region IOrderDetail Interface

		Acme.Northwind.EFDAL.Interfaces.Entity.IProduct Acme.Northwind.EFDAL.Interfaces.Entity.IOrderDetail.Order_details_productsProduct
		{
			get { return this.Order_details_productsProduct; }
			set { this.Order_details_productsProduct = (Acme.Northwind.EFDAL.Entity.Product)value; }
		}

		#endregion

		#endregion

		#region Static SQL Methods

		internal static string GetFieldAliasFromFieldNameSqlMapping(string alias)
		{
			alias = alias.Replace("[", string.Empty).Replace("]", string.Empty);
			switch (alias.ToLower())
			{
				case "discount": return "discount";
				case "orderid": return "orderid";
				case "productid": return "productid";
				case "quantity": return "quantity";
				case "unitprice": return "unitprice";
				case "createddate": return "createddate";
				case "createdby": return "createdby";
				case "modifieddate": return "modifieddate";
				case "modifiedby": return "modifiedby";
				case "timestamp": return "timestamp";
				default: throw new Exception("The select clause is not valid.");
			}
		}

		internal static string GetTableFromFieldAliasSqlMapping(string alias)
		{
			switch (alias.ToLower())
			{
				case "discount": return "Order Details";
				case "orderid": return "Order Details";
				case "productid": return "Order Details";
				case "quantity": return "Order Details";
				case "unitprice": return "Order Details";
				case "createdby": return "Order Details";
				case "createddate": return "Order Details";
				case "modifiedby": return "Order Details";
				case "modifieddate": return "Order Details";
				case "timestamp": return "Order Details";
				default: throw new Exception("The select clause is not valid.");
			}
		}

		internal static string GetTableFromFieldNameSqlMapping(string field)
		{
			switch (field.ToLower())
			{
				case "discount": return "Order Details";
				case "orderid": return "Order Details";
				case "productid": return "Order Details";
				case "quantity": return "Order Details";
				case "unitprice": return "Order Details";
				case "createdby": return "Order Details";
				case "createddate": return "Order Details";
				case "modifiedby": return "Order Details";
				case "modifieddate": return "Order Details";
				case "timestamp": return "Order Details";
				default: throw new Exception("The select clause is not valid.");
			}
		}

		internal static string GetRemappedLinqSql(string sql, string parentAlias, LinqSQLFromClauseCollection childTables)
		{
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[discount\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Order Details") + "].[discount]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[orderid\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Order Details") + "].[orderid]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[productid\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Order Details") + "].[productid]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[quantity\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Order Details") + "].[quantity]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[unitprice\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Order Details") + "].[unitprice]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[createdby\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Order Details") + "].[createdby]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[createddate\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Order Details") + "].[createddate]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[modifiedby\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Order Details") + "].[modifiedby]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[modifieddate\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Order Details") + "].[modifieddate]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[timestamp\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Order Details") + "].[timestamp]", RegexOptions.IgnoreCase);
			return sql;
		}

		#endregion

		#region DeleteData

		/// <summary>
		/// Delete all records that match a where condition
		/// </summary>
		/// <param name="where">The expression that determines the records deleted</param>
		/// <returns>The number of rows deleted</returns>
		public static int DeleteData(Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, bool>> where)
		{
			return DeleteData(where, new nHydrate.EFCore.DataAccess.QueryOptimizer());
		}

		/// <summary>
		/// Delete all records that match a where condition
		/// </summary>
		/// <param name="where">The expression that determines the records deleted</param>
		/// <param name="optimizer">The optimization object to use for running queries</param>
		/// <returns>The number of rows deleted</returns>
		public static int DeleteData(Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, bool>> where, nHydrate.EFCore.DataAccess.QueryOptimizer optimizer)
		{
			if (optimizer == null) throw new Exception("The 'optimizer' parameter cannot be null.");

			var dc = new DataContext(Acme.Northwind.EFDAL.DBHelper.GetConnection());
			var  template = dc.GetTable<Acme.Northwind.EFDAL.OrderDetailQuery>();
			var cmd = nHydrate.EFCore.DataAccess.BusinessEntityQuery.GetCommand<Acme.Northwind.EFDAL.OrderDetailQuery>(dc, template, where);
			cmd.CommandTimeout = 30;

			var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.Table);
			string sql = "SELECT [t0].[OrderID], [t0].[ProductID] INTO #t\r\n";
			sql += parser.GetFromClause(optimizer) + "\r\n";
			sql += parser.GetWhereClause();
			sql += "\r\n";

			var noLock = string.Empty;
			noLock = (optimizer.NoLocking ? "WITH (NOLOCK) " : string.Empty);
			sql += "DELETE [Order Details] FROM [dbo].[Order Details] " + noLock + "INNER JOIN #t ON [dbo].[Order Details].[OrderID] = #t.[OrderID] AND [dbo].[Order Details].[ProductID] = #t.[ProductID]\r\n";
			sql += ";select @@rowcount";
			cmd.CommandText = sql;
			dc.Connection.Open();
			var startTime = DateTime.Now;
			object p = cmd.ExecuteScalar();
			var endTime = DateTime.Now;
			optimizer.TotalMilliseconds = (long)endTime.Subtract(startTime).TotalMilliseconds;
			dc.Connection.Close();
			return (int)p;
		}

		#endregion

		#region UpdateData

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, int>> select, Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, bool>> where, int newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.OrderDetail, Acme.Northwind.EFDAL.OrderDetailQuery, int>.UpdateData(select, where, newValue, "Order Details", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, int?>> select, Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, bool>> where, int? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.OrderDetail, Acme.Northwind.EFDAL.OrderDetailQuery, int?>.UpdateData(select, where, newValue, "Order Details", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, Single>> select, Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, bool>> where, Single newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.OrderDetail, Acme.Northwind.EFDAL.OrderDetailQuery, Single>.UpdateData(select, where, newValue, "Order Details", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, Single?>> select, Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, bool>> where, Single? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.OrderDetail, Acme.Northwind.EFDAL.OrderDetailQuery, Single?>.UpdateData(select, where, newValue, "Order Details", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, decimal>> select, Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, bool>> where, decimal newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.OrderDetail, Acme.Northwind.EFDAL.OrderDetailQuery, decimal>.UpdateData(select, where, newValue, "Order Details", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, decimal?>> select, Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, bool>> where, decimal? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.OrderDetail, Acme.Northwind.EFDAL.OrderDetailQuery, decimal?>.UpdateData(select, where, newValue, "Order Details", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, double>> select, Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, bool>> where, double newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.OrderDetail, Acme.Northwind.EFDAL.OrderDetailQuery, double>.UpdateData(select, where, newValue, "Order Details", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, double?>> select, Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, bool>> where, double? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.OrderDetail, Acme.Northwind.EFDAL.OrderDetailQuery, double?>.UpdateData(select, where, newValue, "Order Details", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, short>> select, Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, bool>> where, short newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.OrderDetail, Acme.Northwind.EFDAL.OrderDetailQuery, short>.UpdateData(select, where, newValue, "Order Details", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, short?>> select, Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, bool>> where, short? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.OrderDetail, Acme.Northwind.EFDAL.OrderDetailQuery, short?>.UpdateData(select, where, newValue, "Order Details", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, string>> select, Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, bool>> where, string newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.OrderDetail, Acme.Northwind.EFDAL.OrderDetailQuery, string>.UpdateData(select, where, newValue, "Order Details", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, DateTime>> select, Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, bool>> where, DateTime newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.OrderDetail, Acme.Northwind.EFDAL.OrderDetailQuery, DateTime>.UpdateData(select, where, newValue, "Order Details", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, DateTime?>> select, Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, bool>> where, DateTime? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.OrderDetail, Acme.Northwind.EFDAL.OrderDetailQuery, DateTime?>.UpdateData(select, where, newValue, "Order Details", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, bool>> select, Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, bool>> where, bool newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.OrderDetail, Acme.Northwind.EFDAL.OrderDetailQuery, bool>.UpdateData(select, where, newValue, "Order Details", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, bool?>> select, Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, bool>> where, bool? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.OrderDetail, Acme.Northwind.EFDAL.OrderDetailQuery, bool?>.UpdateData(select, where, newValue, "Order Details", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, Guid>> select, Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, bool>> where, Guid newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.OrderDetail, Acme.Northwind.EFDAL.OrderDetailQuery, Guid>.UpdateData(select, where, newValue, "Order Details", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, Guid?>> select, Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, bool>> where, Guid? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.OrderDetail, Acme.Northwind.EFDAL.OrderDetailQuery, Guid?>.UpdateData(select, where, newValue, "Order Details", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, byte[]>> select, Expression<Func<Acme.Northwind.EFDAL.OrderDetailQuery, bool>> where, byte[] newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.OrderDetail, Acme.Northwind.EFDAL.OrderDetailQuery, byte[]>.UpdateData(select, where, newValue, "Order Details", GetDatabaseFieldName, true);
		}

		#endregion

		#region GetDatabaseFieldName

		/// <summary>
		/// Returns the actual database name of the specified field.
		/// </summary>
		internal static string GetDatabaseFieldName(OrderDetail.FieldNameConstants field)
		{
			return GetDatabaseFieldName(field.ToString());
		}

		/// <summary>
		/// Returns the actual database name of the specified field.
		/// </summary>
		internal static string GetDatabaseFieldName(string field)
		{
			switch (field)
			{
				case "Discount": return "Discount";
				case "OrderID": return "OrderID";
				case "ProductID": return "ProductID";
				case "Quantity": return "Quantity";
				case "UnitPrice": return "UnitPrice";
				case "CreatedBy": return "CreatedBy";
				case "CreatedDate": return "CreatedDate";
				case "ModifiedBy": return "ModifiedBy";
				case "ModifiedDate": return "ModifiedDate";
				case "Timestamp": return "Timestamp";
			}
			return string.Empty;
		}

		#endregion

		#region Context

		NorthwindEntities IEntityWithContext.Context
		{
			get { return _internalContext; }
			set { _internalContext = value; }
		}
		private NorthwindEntities _internalContext = null;

		#endregion

		#region Auditing
		string nHydrate.EFCore.DataAccess.IAuditable.CreatedBy
		{
			get { return this.CreatedBy; }
		}

		System.DateTime? nHydrate.EFCore.DataAccess.IAuditable.CreatedDate
		{
			get { return this.CreatedDate; }
		}

		bool nHydrate.EFCore.DataAccess.IAuditable.IsCreateAuditImplemented
		{
			get { return true; }
		}

		bool nHydrate.EFCore.DataAccess.IAuditable.IsModifyAuditImplemented
		{
			get { return true; }
		}

		bool nHydrate.EFCore.DataAccess.IAuditable.IsTimestampAuditImplemented
		{
			get { return true; }
		}

		string nHydrate.EFCore.DataAccess.IAuditable.ModifiedBy
		{
			get { return this.ModifiedBy; }
		}

		System.DateTime? nHydrate.EFCore.DataAccess.IAuditable.ModifiedDate
		{
			get { return this.ModifiedDate; }
		}

		byte[] nHydrate.EFCore.DataAccess.IAuditable.TimeStamp
		{
			get { return this.Timestamp; }
		}

		internal virtual void ResetModifiedBy(string modifier)
		{
			if (this.ModifiedBy != modifier)
				this.ModifiedBy = modifier;
		}

		internal virtual void ResetCreatedBy(string modifier)
		{
			if (this.CreatedBy != modifier)
				this.CreatedBy = modifier;
			this.ResetModifiedBy(modifier);
		}
		#endregion

		#region Static Methods

		/// <summary>
		/// Select a single element by its primary key value
		/// </summary>
		public static Acme.Northwind.EFDAL.Entity.OrderDetail SelectByPK(int orderID, int productID)
		{
			using (var context = new Acme.Northwind.EFDAL.NorthwindEntities())
			{
				return context.OrderDetail.FirstOrDefault(x => x.OrderID == orderID && x.ProductID == productID);
			}
		}

		/// <summary>
		/// Returns a list of distinct values based on a predicate
		/// </summary>
		public static IEnumerable<T> GetDistinct<T>(System.Linq.Expressions.Expression<Func<Acme.Northwind.EFDAL.Entity.OrderDetail, T>> select, System.Linq.Expressions.Expression<Func<OrderDetail, bool>> predicate)
		{
			using (var context = new Acme.Northwind.EFDAL.NorthwindEntities())
			{
				return context.OrderDetail.Where(predicate).Select(select).Distinct().ToList();
			}
		}

		/// <summary>
		/// Returns a count of items based on a predicate
		/// </summary>
		public static int GetCount(System.Linq.Expressions.Expression<Func<Acme.Northwind.EFDAL.Entity.OrderDetail, bool>> predicate)
		{
			using (var context = new Acme.Northwind.EFDAL.NorthwindEntities())
			{
				return context.OrderDetail.Count(predicate);
			}
		}

		/// <summary>
		/// Returns a maximum property value of based on a predicate
		/// </summary>
		public static T GetMax<T>(System.Linq.Expressions.Expression<Func<Acme.Northwind.EFDAL.Entity.OrderDetail, T>> select, System.Linq.Expressions.Expression<Func<Acme.Northwind.EFDAL.Entity.OrderDetail, bool>> predicate)
		{
			using (var context = new Acme.Northwind.EFDAL.NorthwindEntities())
			{
				return context.OrderDetail.Where(predicate).Select(select).Max();
			}
		}

		/// <summary>
		/// Returns a minimum property value of based on a predicate
		/// </summary>
		public static T GetMin<T>(System.Linq.Expressions.Expression<Func<Acme.Northwind.EFDAL.Entity.OrderDetail, T>> select, System.Linq.Expressions.Expression<Func<Acme.Northwind.EFDAL.Entity.OrderDetail, bool>> predicate)
		{
			using (var context = new Acme.Northwind.EFDAL.NorthwindEntities())
			{
				return context.OrderDetail.Where(predicate).Select(select).Min();
			}
		}

		/// <summary>
		/// Creates and returns a metadata object for an entity type
		/// </summary>
		/// <returns>A metadata object for the entity types in this assembly</returns>
		public static Acme.Northwind.EFDAL.Interfaces.Entity.Metadata.OrderDetailMetadata GetMetadata()
		{
			var a = typeof(OrderDetail).GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.MetadataTypeAttribute), true).FirstOrDefault();
			if (a == null) return null;
			var t = ((System.ComponentModel.DataAnnotations.MetadataTypeAttribute)a).MetadataClassType;
			if (t == null) return null;
			return Activator.CreateInstance(t) as nHydrate.EFCore.DataAccess.IMetadata as Acme.Northwind.EFDAL.Interfaces.Entity.Metadata.OrderDetailMetadata;
		}

		#endregion

		#region Equals
		bool System.IEquatable<Acme.Northwind.EFDAL.Interfaces.Entity.IOrderDetail>.Equals(Acme.Northwind.EFDAL.Interfaces.Entity.IOrderDetail other)
		{
			return this.IsEquivalent(other);
		}
		#endregion

		#region IDataErrorInfo
		/// <summary>
		/// 
		/// </summary>
		string System.ComponentModel.IDataErrorInfo.Error
		{
			get { return this.GetObjectDataErrorInfo(); }
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="columnName"></param>
		/// <returns></returns>
		string System.ComponentModel.IDataErrorInfo.this[string columnName]
		{
			get
			{
				if (string.IsNullOrEmpty(columnName))
					return string.Empty;

				var retval = GetObjectPropertyDataErrorInfo(columnName);
				if (string.IsNullOrEmpty(retval))
				{
					switch (columnName.ToLower())
					{
						default:
							break;
					}
				}
				return retval;
			}
		}
		#endregion

	}

	partial class OrderDetail : nHydrate.EFCore.DataAccess.ICreatedAudit, nHydrate.EFCore.DataAccess.IModifiedAudit, nHydrate.EFCore.DataAccess.IConcurrencyAudit
	{
		#region ICreatedAudit Members

		string ICreatedAudit.CreatedBy
		{
			get { return this.CreatedBy; }
		}

		DateTime? ICreatedAudit.CreatedDate
		{
			get { return this.CreatedDate; }
		}

		#endregion

		#region IModifiedAudit Members

		string IModifiedAudit.ModifiedBy
		{
			get { return this.ModifiedBy; }
		}

		DateTime? IModifiedAudit.ModifiedDate
		{
			get { return this.ModifiedDate; }
		}

		#endregion

		#region IConcurrencyAudit Members

		byte[] IConcurrencyAudit.TimeStamp
		{
			get { return this.Timestamp; }
		}

		#endregion

	}

}

